#include<bits/stdc++.h>
using namespace std;
int tree[40005];
int T,n,m,bsabi[10005],asks[10005],battles[40][10005],abb[8];//youdianruozhi
void buildtree(int id,int l,int r){
    if(r=l+1){
        if(battles[1][r/2]==0){
            if(l<1){
                tree[id]=r;
            }else{
                tree[id]=l;
            }
        }else{
            if(r<1){
                tree[id]=l;
            }else{
                tree[id]=r;
            }
        }return;
    }
    int a=((r-l)+1)/2;
    buildtree(id*2,l+a,r);
    buildtree(id*2+1,l,r-a);
    if(battles[int(log2(r-l+1))][r>>(int(log2(r-l+1)))]==0){
        if(tree[id>>1]<int(log2(r-l+1))){
            tree[id]=r;
        }else{
            tree[id]=l;
        }
    }else{
        if(tree[id>>1+1]<int(log2(r-l+1))){
            tree[id]=l;
        }else{
            tree[id]=r;
        }
    }
}
int main(){
    //freopen("arena.in","r",stdin);
    //freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>bsabi[i];
    for(int i=1;i<=m;i++)cin>>asks[i];
    int K=int(log2(n-1))+1;
    for(int i=1;i<=K;i++){
        string u;
        cin>>u;
        for(int j=1;j<=2<<(K-i);j++){
            battles[i][j]=(u[j]-'0');
        }
    }
    cin>>T;
    while(T--){
        int ans=0;
        for(int i=0;i<=3;i++){
            cin>>abb[i];
        }int ability[10005];
        for(int i=1;i<=n;i++){
            ability[i]=bsabi[i]+abb[i%4];
        }//yuchuli
        buildtree(1,1,2<<(K-1));
        for(int i=1;i<=m;i++){
            if(asks[i]==1){
                ans^=1;
                continue;
            }
            int k=int(log2(asks[i]-1))+1;
            ans^=tree[1<<k];
        }cout<<ans<<endl;
    }
    return 0;
}
/*
            ****
          ********
         ***     **
         ***     **
           *    *
             **
            *  *
       *****    *****
      *  *         * *
     *                *
    *                  *
    *                  *
    *                  *
    *                  *
     *                *
    *
   *
  *
  *
  *
  *
  *
 ******
*/
